package com.archetypus.projectschedule.web.involvements.cmd;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.archetypus.projectschedule.common.dto.activities.Activity;
import com.archetypus.projectschedule.common.dto.involvements.Involvement;
import com.archetypus.projectschedule.common.dto.involvements.InvolvementKey;
import com.archetypus.projectschedule.common.dto.projects.Project;
import com.archetypus.projectschedule.common.exceptions.ProjectSchedulerException;
import com.archetypus.projectschedule.web.common.cmd.ICommand;
import com.archetypus.projectschedule.web.involvements.bd.IInvolvementBD;
import com.archetypus.projectschedule.web.involvements.bd.InvolvementBD;

public class FindInvolvementCmd implements ICommand {

	public void execute(HttpServletRequest request, HttpServletResponse response) throws ProjectSchedulerException {
		Project project = (Project)request.getAttribute("project");
		Activity activity = (Activity)request.getAttribute("activity");
		int responsible = Integer.parseInt(request.getParameter("responsible"));
		
		InvolvementKey involvementKey = new InvolvementKey();
		involvementKey.setActivity(activity.getActivityKey().getId());
		involvementKey.setProject(project.getProjectKey().getId());
		involvementKey.setResponsible(responsible);
		
		Involvement involvement = new Involvement();
		involvement.setInvolvementKey(involvementKey);
		
		IInvolvementBD involvementBD = new InvolvementBD();
		Involvement selectedInvolvement = involvementBD.findInvolvement(involvement);
		
		request.setAttribute("involvement", selectedInvolvement);
	}

}
